//
//  SWProductListViewController.m
//  sc-cyan-ios
//
//  Created by lvjian01 on 2017/12/20.
//  Copyright © 2017年 greenbuilding. All rights reserved.
//

#import "SWProductListViewController.h"
#import "SWSearchListCollectionViewCell.h"
#import "SWSearchNaviView.h"

@interface SWProductListViewController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDelegate,UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *headerView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@property (nonatomic, strong) SWSearchNaviView *searchNaviView;
@property (nonatomic, strong) NSMutableArray *productLists;



@end

@implementation SWProductListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.productLists = [NSMutableArray arrayWithArray:@[@"kjhgkhgjk",@"adfsad",@"adsfasdf"]];



}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:self.searchNaviView];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.searchNaviView removeFromSuperview];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (SWSearchNaviView *)searchNaviView{
    if (!_searchNaviView) {
        _searchNaviView = [[SWSearchNaviView alloc] initWithFrame:self.navigationController.navigationBar.bounds];
        MJWeakSelf
        _searchNaviView.popViewBack = ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        };
        
        _searchNaviView.searchText = ^(NSString *text) {
//            搜索新数据
            
            
            [weakSelf.collectionView reloadData];
        };
        
    }
    return _searchNaviView;
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.productLists.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    SWSearchListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SWSearchListCollectionViewCell class]) forIndexPath:indexPath];
    
    
    
    // Configure the cell
    
    return cell;
}

#pragma mark -- UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((Main_Screen_Width - 30) / 2, (Main_Screen_Width - 30) / 2 + 60);
}

#pragma mark <UICollectionViewDelegate>


@end
